package com.ybu;

import java.util.HashMap;
import java.util.Map;

public class MapPractice {
    public static void main (String[] args) {

        Map<String, String> data = new HashMap<>();
        data.put("小李","A");
        data.put("小王","B");
        data.put("小张","C");
        data.put("小赵","D");
        data.put("小孙","D");
        data.put("小ju","A");
        data.put("小小","B");
        data.put("小lo","D");
        data.put("小tom","A");
        data.put("小jerry","A");
        data.put("小cat","C");
        data.put("小dog","A");
        count(data);
    }
    public static void count(Map<String, String> data) {
        //1.创建一个新的map集合，存储统计结果
        //2.遍历data集合
        //3.获取value值，将value当作key存储到新的集合中
        //4.获取value值，如果value值在map集合中存在，则value值+1，如果不存在，则value值=1
        //5.遍历map集合，打印统计结果
        Map<String, Integer> reult = new HashMap<>();
        data.forEach((k,v)->{
           boolean  containsKey = reult.containsKey(v);
           if(containsKey){
               reult.put(v,reult.get(v)+1);
           }else{
               reult.put(v,1);
           }
        });
        //遍历集合
        reult.forEach((k,v)->{
            System.out.println(k + ":" + v);
        });
    }
}
